#include <linux/init.h>
#include <linux/module.h>
#include <linux/list.h>
#include <linux/sched.h> /* init_task */

MODULE_LICENSE("Dual BSD/GPL");

static int list_process_init(void)
{
	struct task_struct *p = NULL, *task = NULL;
	struct list_head *pos = NULL;
	int count = 0;

	printk(KERN_EMERG "%s(),line %d\n", __FUNCTION__, __LINE__);
	task = &init_task;

	list_for_each(pos, &task->tasks)
	{
		p = list_entry(pos, struct task_struct, tasks);
		count++;
		printk(KERN_EMERG "pid %d--->%s\n", p->pid, p->comm);
	}

	printk(KERN_EMERG "the number of process is %d\n", count);

	return 0;
}

static void list_process_exit(void)
{
	printk(KERN_EMERG "%s(),line %d\n", __FUNCTION__, __LINE__);
}

module_init(list_process_init);
module_exit(list_process_exit);
